(function () {
	var ns = ij.pkg('core').namespaceString;
	ij.core.Controls = ij.core.Force.extend({
		init: function (config) {
			return this._super(ij.apply({
				classname: ns + '.Controls',
				gameObject: null,
			}, config));
		},
		attachTo: function (gameObject) {
			this.gameObject = gameObject;
			
			return this;
		},
		startAction: function (keyCode) {
			var action = this.actions[this.actionMap[keyCode]];
			if (action && !action.active) {
				action.active = true;
			}
			return this;
		},
		stopAction: function (keyCode) {
			var action = this.actions[this.actionMap[keyCode]];
			if (action && action.active) {
				action.active = false;
			}
			return this;
		},
		moveLeft: function () {
			if (this.gameObject.state != 'midair') {
				this.gameObject.setState('move');
			}
			this.gameObject.fX = -10;
			
			return this;
		},
		moveRight: function () {
			if (this.gameObject.state != 'midair') {
				this.gameObject.setState('move');
			}
			this.gameObject.fX = 10;
			
			return this;
		},
		moveUp: function () {
			if (this.gameObject.state != 'midair') {
				this.gameObject.setState('midair');
				this.gameObject.fY = -10;
			}
			
			return this;
		},
		moveDown: function () {
			
			return this;
		},
		applyOn: function () {
			if (this.gameObject) {
				ij.each(this.actions, function (i, item) {
					if (item.active) {
						item.callback.call(this);
					}
				}, this);
			}
			
			return this;
		}
	});
})();